package com.ynny.controller;

import com.ynny.entity.ResultData;
import com.ynny.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
//@Controller
//@ResponseBody
@RequestMapping("/json")
public class DataBindTest02Controller {


    @PostMapping("/test01")
    public String test01(@RequestBody User user) {

        System.out.println(user);
        return "test01";

    }

    @PostMapping("/test02")
    public User test02(@RequestBody User user) {

        System.out.println(user);
        return user;

    }


    @PostMapping("/test03")
    public List<Object> test03(@RequestBody User user) {

        ArrayList<Object> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(user);
        }

        return list;

    }


    @PostMapping("/test04")
    public ResultData test04(@RequestBody User user) {

        ArrayList<Object> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(user);
        }

//        return ResultData.ok(200, "成功", list);

        ResultData resultData = new ResultData();
        resultData.setCode(200);
        resultData.setMessage("成功");
        resultData.setData(list);
        return resultData;
    }



}
